<template>
  <div class="app-container">
    <el-tabs v-model="activeName">
      <el-tab-pane v-permission="['sys:list']" :id="1" label="管理员操作日志" name="op_logs" class="margin-10">
        <div class="filter-container">
          <el-input v-model="listQuery.name" clearable class="filter-item" style="width: 200px;" placeholder="搜索管理员账号"/>
          <el-button class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">查找</el-button>
        </div>

        <el-table v-loading="listLoading" :data="list" size="small" element-loading-text="正在查询中..." border fit highlight-current-row>
          <el-table-column align="center" label="ID" width="100" prop="id" />
          <el-table-column align="center" label="管理员" width="120" prop="userName" />
          <el-table-column align="center" label="操作" prop="title" width="150"/>
          <el-table-column align="center" label="IP" prop="ip" width="150"/>
          <el-table-column align="center" label="结果" prop="success" width="100">
            <template slot-scope="scope">
              <el-tooltip v-if="!scope.row.success" :content="scope.row.content" class="item" effect="dark" placement="top">
                <el-link type="danger">失败</el-link>
              </el-tooltip>
              <el-link v-else :underline="false" type="success">成功</el-link>
            </template>
          </el-table-column>
          <el-table-column align="center" width="200" label="操作时间" prop="time"/>
          <el-table-column align="left" label="URL" prop="url"/>
        </el-table>
        <pagination v-permission="['sys:list']" v-show="total>0" :total="total" :page.sync="listQuery.pageNo" :limit.sync="listQuery.pageSize" @pagination="getList"/>
      </el-tab-pane>
      <el-tab-pane v-permission="['login:list']" :lazy="true" :id="2" label="管理员登录日志" name="login_logs" class="margin-10">
        <login-log/>
      </el-tab-pane>
      <el-tab-pane v-permission="['user:list']" :lazy="true" :id="3" label="用户操作日志" name="user_logs" class="margin-10">
        <user-log/>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import { LogsService } from '@/api/SystemService'
import Pagination from '@/components/Pagination'
import LoginLog from '@/views/system/login_log'
import UserLog from '@/views/system/user_log'

export default {
  name: 'AdminLog',
  components: { Pagination, LoginLog, UserLog },
  data() {
    return {
      activeName: 'op_logs',
      list: null, total: 0, listLoading: true,
      listQuery: { pageNo: 1, pageSize: 20, name: undefined }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      this.listLoading = true
      LogsService.listSysLog(this.listQuery).then(response => {
        this.list = response.data
        this.total = response.totalCount
        this.listLoading = false
      })
    },
    handleFilter() {
      this.listQuery.pageNo = 1
      this.getList()
    }
  }
}
</script>

<style>
</style>
